﻿<html>

	<head>
		<title>订单详情管理</title>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">

		<link href="../../css/skin/default/style.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="../../css/dialog.css">
		<link href="../../js/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />

		<script src="../../js/lib/jquery/jquery-1.10.2.min.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>

		<script src="../../js/lib/ligerUI/js/plugins/ligerPopupEdit.js"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerLayout.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerRadio.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerDrag.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerResizable.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerMenu.js" type="text/javascript"></script>
		<script src="../../js/lib/ligerUI/js/plugins/ligerToolBar.js" type="text/javascript"></script>
		<script src="../../js/lib/jquery.form.js" type="text/javascript"></script>
		<script src="../../js/lib/json2.js" type="text/javascript"></script>
		<script src="../../js/dialog.js"></script>
		<script src="../../js/JS/layout.js"></script>
		<script src="../../js/constants.js" type="text/javascript"></script>
		<script src="../../js/api.js" type="text/javascript"></script>

		<script type="text/javascript">
			var manager;
			var Fcode = $api.getparastr("Fcode");
			var row;
			var saleUrl = BaseUrl + "sale/storedetail?token=" + $api.getStorage("token");
			$(function() {
				$("form").ligerForm();
				initData();

			});

			function initData() {
				var url = saleUrl + "&code=" + Fcode;
				$api.ajaxget(url, {}, function(res) {
					row = res;
					if(!res.Head) {
						top.$.ligerDialog.error("订单不存在！", function() {
							windows.History.go(-1);
						});
					} else {
						initGrid(res.data.saledetail);
						initView(res.data.sale);
					}

				});

			}

			function initGrid(data) {

				var rows = {
					"Rows": data,
					"Total": data.length
				}
				manager = $("#maingrid").ligerGrid({
					columns: [{
							display: '标题',
							name: 'PDesc',
							align: 'left',
							minWidth: 280,
							render: function(rowdata, rowindex, value) { 
								var ret = "<img src=" + rowdata.Fimg + " class='listimgs' style='float:left;top:5px' />";
								ret += "<div style='float:left; margin-left:5px'><span>" + rowdata.Fpname + "</span>";
								ret += "<br/><span style='color:#999'>" + rowdata.Detail.Ft1 + "</span>"

								ret += "</div>"
								return ret;
							}
						},
						{
							display: '货号',
							name: 'Fpcode',
							align: 'left',
							width: 120,
							isSort: true
						},
						{
							display: '条码',
							name: 'Fbarcode',
							align: 'left',
							width: 120
						},
						{
							display: '箱装数',
							name: 'Ft1',
							align: 'left',
							width: 120
						},

						{
							display: '单价',
							name: 'Fprice',
							type: 'currency',
							width: 100,
							align: 'right'
						},
						{
							display: '数量',
							name: 'Fnum',
							type: 'number',
							width: 80,
							align: 'left'
						},
						{
							display: '金额',
							name: 'Fmoney',
							type: 'currency',
							width: 100,
							align: 'left'
						},
						{
							display: '体积',
							name: 'Fc6',
							align: 'left',
							width: 120,
							render: function(rowdata, rowindex, value) {
								if(rowdata.Fc6) {
									return(rowdata.Fc6 * rowdata.Fnum).toFixed(6) + "立方米";
								}
								return "";
							}
						},
						{
							display: '毛重',
							name: 'Fc2',
							align: 'left',
							width: 120,
							render: function(rowdata, rowindex, value) {
								if(rowdata.Fc2) {
									return(rowdata.Fc2 * rowdata.Fnum).toFixed(3) + "KG";
								}
								return "";
							}
						},
						{
							display: '净重',
							name: 'Fc7',
							align: 'left',
							width: 120,
							render: function(rowdata, rowindex, value) {
								if(rowdata.Fc7) {
									return(rowdata.Fc7 * rowdata.Fnum).toFixed(3) + "KG";
								}
								return "";
							}
						}

					],
					data: rows,
					width: '99.5%',
					isScroll: true,
					rowHeight: 100,
					pageSize: 50,
					usePager: true
				});
			}

			function noteStatus(rowdata) {

				if(rowdata.Head.Fstatus == 2)
					return "待发货";
				if(rowdata.Head.Fstatus == 3)
					return "部分发货";
				if(rowdata.Head.Fstatus == 4)
					return "发货已完成";
				if(rowdata.Head.Fstatus == 6)
					return "订单已完成";
			}

			function initView(rowdata) {
				var Fdate = rowdata.Head.Fdate = rowdata.Head.Fdate.replace("T", " ");
				var i = rowdata.Head.Fdate.indexOf('.');
				rowdata.Head.Fdate = rowdata.Head.Fdate.substr(0, i);

				var deal = "<span style='margin-left:5px'>交易流水号:</span><span style='color:#333'>" + rowdata.Head.Fcode + "</span>";

				deal += "<span style='margin-left:5px'>订单金额:￥</span><span id='Ftotal' style='color:red;font-size:22px'>" + rowdata.Head.Ftotalmoney + "</span>";
				deal += "<span style='margin-left:5px'>状态:【" + noteStatus(rowdata) + "】</span>"
				deal += "<span style='margin-left:5px;color:#333'>下单时间:" + Fdate + "</span>";

				$("#deal").append(deal);

				if(rowdata.Head.Fstatus > 2)
					$("#courier").css("display", "block");

				if(!$api.isEmpty(rowdata.Head.Fmemo)) {
					let address += "<tr><td>买家留言:" + rowdata.Head.Fmemo + "</td></tr>";
					$("#address").append(address);
				}

				var ret = "";
				//非活动订单
				if(rowdata.Head.Faid == 0) { 
					//已付款待发货，已发部分货
					if(rowdata.Head.Fstatus == 2 || rowdata.Head.Fstatus == 3) {
						ret += "<a class='btn yellow' onclick='SendDriver();'>发货</a>" +
							"<a style='margin-left:5px;margin-top:5px;' class='btn green' onclick='Return();'>退货</a>";
					}
				}
				 
				if(!$api.isEmpty(ret))
					$("#btns").append(ret);
				else
					$("#btns").css("display", "none");

			}

			//发货
			function SendDriver() {
				 
				window.location.href = "SendMail.html?Fcode=" + Fcode;
			}
			 
			//退货
			function Return(i) {
				window.location.href = "Return.html?Fcode=" + Fcode; 
			}

			 

			function Mail() {
				window.location.href = "SendMailDetail.html?Fcode=" + Fcode;
			}
		</script>

	</head>

	<body class="mainbody">
		<form id="form1" onsubmit="return false">
			<!--导航栏-->
			<div class="location" width="300px">
				<table>
					<tr> 
						<td>
							<span style="margin-left:10px">交易管理</span>
							<i class="arrow"></i>
							<span class="nows">交易详单</span> </td>
					</tr>
				</table>
			</div>

			<div class="line10"></div>
			<!--/导航栏-->
			<div class="toolbar-wrap">
				<div class="toolbar">

					<!--收货地址 -->
					<div style=" margin-left:15px;font-size:12px;line-height:30px;">
						<table cellspacing="4px" cellpadding="4px" id="address">
						</table>
					</div>
					<!--物流信息 -->
					<div id="courier" style="display: none;margin-left:15px;font-size:12px;line-height:30px;">
						<a onclick="Mail();" class="btn green">发货详情</a>
						 

					</div>
					<!--物流信息 -->
					<div id="btns" style="line-height:30px;float:left;margin-left:15px;">
					</div>
				</div>
			</div>
			<div id="deal" style="padding: 3px; background: #f3f3f3;width:99%;font-size:13px;line-height:22px;border: 1px solid #ddd;"></div>

			<!--订单详情-->
			<div id="maingrid" style="margin: 0px;background:#fff;"></div>

		</form>

	</body>

</html>